import request from './request'

export interface UserItem {
  id: number;
  username: string;
  role: string;
  user_type: number;
  address?: string;
  contact?: string;
}

export interface UserListResponse {
  total: number;
  list: UserItem[];
}

export function getUserList(params: { page?: number; pageSize?: number; keyword?: string }): Promise<UserListResponse> {
  return request<UserListResponse>({
    url: '/user',
    method: 'get',
    params
  })
}

export function getUserDetail(id: number) {
  return request({
    url: `/user/${id}`,
    method: 'get'
  })
}

export function createUser(data: any) {
  return request({
    url: '/user',
    method: 'post',
    data
  })
}

export function updateUser(id: number, data: any) {
  return request({
    url: `/user/${id}`,
    method: 'put',
    data
  })
}

export function deleteUser(id: number) {
  return request({
    url: `/user/${id}`,
    method: 'delete'
  })
}
